package proxy.dyn;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @description: 代理控制层 做权限的控制
　* @author 周杨
　* @date 2019/6/13  13:36
**/
public class OwnerInvocationHandler implements InvocationHandler {
    private PersonBean person;
    OwnerInvocationHandler(PersonBean person){
        this.person = person;
    }
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (method.getName().startsWith("get")){
            return method.invoke(person, args);
        }else if ("setHotOrNotRating".equals(method.getName())){
            return new IllegalAccessException();
        }else if (method.getName().startsWith("set")){//可以set
            return method.invoke(person, args);
        }
        return null;
    }
}
